﻿
#pragma once

#define _CRT_SECURE_NO_WARNINGS

#include <Windows.h>
#include <string>
#include <vector>
#include <map>
#include <stdio.h>
#include <wchar.h>
#include <time.h>
#include <queue>
#include "QueueThread.h"

//
#pragma comment( lib,"winmm.lib" )

//
using namespace std;

//
//
#define MSG_LOGW (WM_APP+1000)
#define MSG_LOGA (WM_APP+1001)

//
//
DWORD Now();
void Log(const WCHAR* format, ...);
void Log(const CHAR* format, ...);
CHAR* WChar2Char(WCHAR szStr[]);

//
extern DWORD g_dwLogThread;

//
DWORD LogProc(LPVOID lParam);

//
typedef		unsigned int			UInt;
typedef		unsigned __int64		UInt64;

//
#define PATH_LEN					(MAX_PATH + MAX_PATH / 2)
#define NAME_LEN					(MAX_PATH)
#define ROOT_FILE_REF_NO			(1407374883553285)
#define BUF_LEN						(1024)

//
class CListVolume;

//
class TTask
{
public:
	~TTask();

public:
	UInt iType = 0;

public:
	CListVolume* listVolume;
	UInt64 iFileRefNum;
	CHAR* szName;
};

class MyQueueThread : public MQueueThread
{
public:
	virtual void ProcessQueue(MQueueParam *lpQueueParam);
};

//
class TParamList
{
public:
	CHAR szPath[PATH_LEN];
	CHAR szVolume[3] = "D:"; // 要遍历的磁盘，注意是 D: 有冒号。
};

class TFileInfo
{
public:
	TFileInfo();
	~TFileInfo();

public:
	enum FTYPE
	{
		eUNKNOWN = 0,
		eFILE = 1,
		eDIR = 2
	};

public:
	CHAR  szVolume[3];
	FTYPE  fType;
	UInt64 iParentFileReferenceNumber;
	UInt64 iFileReferenceNumber;
	UInt64 iSize;
	DWORD  iFileAttributes;
	BOOL   bFullPath;

public:
	CHAR*  szName;
	CHAR*  szPath;
};

//
class CListVolume
{
public:
	typedef std::vector<TFileInfo*> FileInfoVector;
	typedef std::map<UInt64, FileInfoVector*> FileInfoMap;

public:
	CListVolume();
	~CListVolume();

public:
	int PostTask(TTask* task);
	int DoTask(TTask* task);

public:
	void AddFile(TFileInfo* _fileInfo);
	void AddFolder(TFileInfo* _fileInfo);

public:
	UInt64 GetFileSize(CHAR szFile[]);

public:
	int BuildFolderPath();
	void BuildFilePath();

public:
	// 遍历 USN
	int ListVolume(TParamList& _param);

public:
	FileInfoMap m_mapFileInfo;
	FileInfoMap m_mapFolderInfo;

public:
	FileInfoVector m_vecFolderInfo;
	FileInfoVector m_vecFileInfo;

public:
	DWORD m_dwDBThreadID;
	HANDLE m_hDBThread;

public:
	MyQueueThread m_queueThread;
};
